//
//  ZYCStuLeaveRecordDetailViewController.m
//  ZDSC
//
//  Created by ZDTX on 2021/7/19.
//

#import "ZYCStuLeaveRecordDetailViewController.h"
#import "ZYCManageCourseSelectDetailCell.h"
#import "ZYCStuLeaveRecordDetailHeaderView.h"
#import "ZYCStuLeaveRecordDetailFooterView.h"
#import "ZYCLeaveRecordDetailModel.h"
#import "ZYCStudentLeaveDetailCell.h"
@interface ZYCStuLeaveRecordDetailViewController ()<UITableViewDataSource,UITableViewDelegate>
@property (nonatomic, strong) UITableView *tableView;
@property (nonatomic, strong) NSArray *dataSource;
@property (nonatomic, strong) ZYCStuLeaveRecordDetailHeaderView *headerView;
@property (nonatomic, strong) ZYCStuLeaveRecordDetailFooterView *footerView;
@property (nonatomic, strong) ZYCLeaveRecordDetailModel *detailModel;
@end

@implementation ZYCStuLeaveRecordDetailViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.title = self.titleString;
    [self.view addSubview:self.tableView];
    self.tableView.tableHeaderView = self.headerView;
    self.tableView.tableFooterView = self.footerView;

    [self loadLeaveRecordDetail];
}

- (void)loadLeaveRecordDetail{
    NSDictionary *params = @{
        @"leaveId":self.leaveId
    };
    [MrjSVProgressHUD showWithStatus:@"加载中..."];
    [[URLManager sharedURLManager] postUrlString:Appliance_Post_QueryDetailById requestService:RequestServiceWorkBench parameters:params progress:^(NSProgress * _Nonnull downloadProgress) {
        
    } success:^(id  _Nullable responseObject) {
        [MrjSVProgressHUD dismiss];
        if (SUCCESS(responseObject[@"code"])) {
            self.detailModel = [ZYCLeaveRecordDetailModel yy_modelWithDictionary:responseObject[@"body"]];
            self.headerView.contentString = self.detailModel.noticePersons;
            self.footerView.model = self.detailModel;
            [self.tableView reloadData];
        }else{
            [MrjToast makeToast:responseObject[@"message"] makeView:self.view];
        }
    } failure:^(NSError * _Nonnull error) {
        
    }];
}

#pragma mark - UITableViewDelegate,UITableViewDataSource
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return self.dataSource.count;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    NSArray *rows = self.dataSource[section];
    return rows.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    ZYCManageCourseSelectDetailCell *cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([ZYCManageCourseSelectDetailCell class]) forIndexPath:indexPath];
    cell.titleString = self.dataSource[indexPath.section][indexPath.row];
    if (indexPath.section == 0) {
        if (indexPath.row == 0) {
            cell.contentString = self.detailModel.durationLeaveName;
            //请假时长（1：上午假；2：下午假；3：全天假）
            if ([self.detailModel.durationLeave integerValue] == 1 ) {
                cell.contentLabel.textColor = HEX_RGB(@"#39A85B");
            }else  if ([self.detailModel.durationLeave integerValue] == 2) {
                cell.contentLabel.textColor = HEX_RGB(@"#395AD2");
            }else if([self.detailModel.durationLeave integerValue] == 3){
                cell.contentLabel.textColor = HEX_RGB(@"#EB9F28");
            }
        }
        if (indexPath.row == 1) {
            cell.contentString = self.detailModel.leaveDate;
        }
    }
    if (indexPath.section == 1) {
        if (indexPath.row == 0) {
            cell.contentString = self.detailModel.durationLeaveName;
        }
        if (indexPath.row == 1) {
            cell.contentString = self.detailModel.className;
        }
        if (indexPath.row == 2) {
            cell.contentString = self.detailModel.submitTime;
        }
    }
    return cell;

}

-(CGFloat) tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 10.0f;
}

-(CGFloat) tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    return 0.01f;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 45.0f;
}

- (nullable UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
    return [UIView new];
}

- (nullable UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    return [UIView new];
}

- (UITableView *)tableView {
    if (!_tableView) {
        _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0,kNavBarAndStatusBarHeight, kScreenWidth, kScreenHeight - kNavBarAndStatusBarHeight) style:UITableViewStyleGrouped];
        _tableView.dataSource = self;
        _tableView.delegate = self;
        _tableView.showsVerticalScrollIndicator = NO;
        _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        _tableView.estimatedSectionFooterHeight = UITableViewAutomaticDimension;
        _tableView.sectionFooterHeight = 300;
        [_tableView registerClass:[ZYCManageCourseSelectDetailCell class] forCellReuseIdentifier:NSStringFromClass([ZYCManageCourseSelectDetailCell class])];
        [_tableView registerClass:[ZYCStudentLeaveDetailCell class] forCellReuseIdentifier:NSStringFromClass([ZYCStudentLeaveDetailCell class])];
        
    }
    return _tableView;
}

- (ZYCStuLeaveRecordDetailHeaderView *)headerView {
    if (!_headerView) {
        _headerView = [[ZYCStuLeaveRecordDetailHeaderView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, 125.0f)];
    }
    return _headerView;
}

- (ZYCStuLeaveRecordDetailFooterView *)footerView {
    if (!_footerView) {
        _footerView = [[ZYCStuLeaveRecordDetailFooterView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, 500.0f)];
    }
    return _footerView;
}
- (NSArray *)dataSource {
    if (!_dataSource) {
        _dataSource = @[
            @[@"请假时长",@"请假日期"],@[@"所在年级",@"所在班级",@"提交时间"]
        ];
    }
    return _dataSource;
}


/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
